
**********************************************************************************
* Analysis File for "When Parents Decide: Gender Differences in Competitiveness" *
* Created by Jonas Tungodden and Alexander Willen				 *
* Last Edited July 15, 2022							 * 
**********************************************************************************



* Opening the log file and choosing settings
************************************************************************************************
version 16
set scheme s2mono
set more off
local School_FE s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 // Used in Figures 2 through 4
global Data "/data/prosjekt/competitive_gender"
global Results "/home/alexander/Whenparentsdecide/"
set cd "$Results/"
log using "$Results/TablesAndFigures.smcl", replace
************************************************************************************************

************
* Figure 1 *
************
* Not Created in Stata

************
* Figure 2 *
************  
{
use "$Data/experimentdata.dta", clear 


	preserve
	keep if child==1
	gen t=_n
	gen h=.
	gen hd=.
	gen ld=.

	reg pchoice girl boy, r nocons
	mat b = e(b)
	mat v= e(V)
	replace h= b[1,1] if t==1
	replace h= b[1,2] if t==2	
	replace hd=h+sqrt(v[1,1]) if t==1
	replace ld=h-sqrt(v[1,1]) if t==1
	replace hd=h+sqrt(v[2,2]) if t==2
	replace ld=h- sqrt(v[2,2]) if t==2

	reg cchoice girl boy, r nocons
	mat b = e(b)
	mat v= e(V)
	replace h= b[1,1] if t==3
	replace h= b[1,2] if t==4
	replace hd=h+sqrt(v[1,1]) if t==3
	replace ld=h-sqrt(v[1,1]) if t==3
	replace hd=h+sqrt(v[2,2]) if t==4
	replace ld=h- sqrt(v[2,2]) if t==4

	local V Figure_2_table_var
	gen `V'=.
	replace `V'=0.5 if t==1
	replace `V'=2 if t==2
	replace `V'=3.5 if t==3
	replace `V'=5 if t==4
	local xlabel xlabel( ///
	0.5 "Daughters" ///
	2 "Sons" ///
	3.5 "Daughters" ///
	5 "Sons" ///
	,  notick )  
	local legend  legend(off)
	local title ytitle(" ")
	local specs xtitle(" ") xtick(none) graphregion(color(white)) yscale(range(0 .7)) ylabel(0 (.1) .7) ytick(0 (.1) .7)
	local text 	text(0.675 1.2 "Panel A:", size(medium)) ///
	text(0.64 1.2 "Parent choice", size(medium)) ///
		text(0.675 4.2 "Panel B", size(medium)) text(0.64 4.2 "Child choice", size(medium)) 
	local line xline(2.75, lpattern(solid)) 
	
	local condition1  `V'==0.5 | `V'==3.5 
	local condition2  `V'==2 | `V'==5  
	graph twoway (bar h `V' if (`condition1'),fcolor(gs16) lcolor(gs0) lwidth(thin)) ///
	(bar h `V' if (`condition2'),fcolor(gs16) lcolor(gs0) lwidth(thin)) ///
	(rcap hd ld `V' if ((`condition1') | (`condition2') ), lcolor(gs0)), ///
	`specs'  `legend' `title' `xlabel' `xscale' `text' `line'

	restore
}

************
* Figure 3 *
************	
use "$Data/experimentdata.dta", clear 
	
{
	preserve
	keep if child==1
	gen t=_n
	gen h=.
	gen hd=.
	gen ld=.

	reg pbelief girl boy, r nocons
	mat b = e(b)
	mat v= e(V)
	replace h= b[1,1] if t==1
	replace h= b[1,2] if t==2	
	replace hd=h+sqrt(v[1,1]) if t==1
	replace ld=h-sqrt(v[1,1]) if t==1
	replace hd=h+sqrt(v[2,2]) if t==2
	replace ld=h- sqrt(v[2,2]) if t==2


	reg pself girl boy, r nocons
	mat b = e(b)
	mat v= e(V)
	replace h= b[1,1] if t==3
	replace h= b[1,2] if t==4
	replace hd=h+sqrt(v[1,1]) if t==3
	replace ld=h-sqrt(v[1,1]) if t==3
	replace hd=h+sqrt(v[2,2]) if t==4
	replace ld=h- sqrt(v[2,2]) if t==4

	
	local V Figure_3_table_var
	gen `V'=.
	replace `V'=0.5 if t==1
	replace `V'=2 if t==2
	replace `V'=3.5 if t==3
	replace `V'=5 if t==4
	local xlabel xlabel( ///
	0.5 "Daughters" ///
	2 "Sons" ///
	3.5 "Daughters" ///
	5 "Sons" ///
	,  notick )  
	local legend  legend(off)
	local title ytitle(" ")
	local specs xtitle(" ") xtick(none) graphregion(color(white)) yscale(range(0 .7)) ylabel(0 (.1) .7) ytick(0 (.1) .7)
	local text 	text(0.675 1.2 "Panel A:", size(medium)) ///
	text(0.64 1.2 "Child perspective", size(medium)) ///
		text(0.675 4.2 "Panel B", size(medium)) text(0.64 4.2 "Parent perspective", size(medium)) 
	local line xline(2.75, lpattern(solid)) 
	
	local condition1  `V'==0.5 | `V'==3.5 
	local condition2  `V'==2 | `V'==5  
	graph twoway (bar h `V' if (`condition1'),fcolor(gs16) lcolor(gs0) lwidth(thin)) ///
	(bar h `V' if (`condition2'),fcolor(gs16) lcolor(gs0) lwidth(thin)) ///
	(rcap hd ld `V' if ((`condition1') | (`condition2') ), lcolor(gs0)), ///
	`specs'  `legend' `title' `xlabel' `xscale' `text' `line' 

	restore
}
	
************
* Figure 4 *
************ 
use "$Data/experimentdata.dta", clear 

{
	preserve
	keep if child==1 
	gen t=_n
	gen h=.
	gen hd=.
	gen ld=.
	
	reg pchoice mother father, r nocons
	mat b = e(b)
	mat v= e(V)
	replace h= b[1,1] if t==1
	replace h= b[1,2] if t==2	
	replace hd=h+sqrt(v[1,1]) if t==1
	replace ld=h-sqrt(v[1,1]) if t==1
	replace hd=h+sqrt(v[2,2]) if t==2
	replace ld=h- sqrt(v[2,2]) if t==2

	reg pbelief mother father, r nocons
	mat b = e(b)
	mat v= e(V)
	replace h= b[1,1] if t==3
	replace h= b[1,2] if t==4
	replace hd=h+sqrt(v[1,1]) if t==3
	replace ld=h-sqrt(v[1,1]) if t==3
	replace hd=h+sqrt(v[2,2]) if t==4
	replace ld=h- sqrt(v[2,2]) if t==4

	reg pself mother father, r nocons
	mat b = e(b)
	mat v= e(V)
	replace h= b[1,1] if t==5
	replace h= b[1,2] if t==6
	replace hd=h+sqrt(v[1,1]) if t==5
	replace ld=h-sqrt(v[1,1]) if t==5
	replace hd=h+sqrt(v[2,2]) if t==6
	replace ld=h- sqrt(v[2,2]) if t==6
	
	local V Figure_4_table_var
	gen `V'=.
	replace `V'=0.5 if t==1
	replace `V'=2 if t==2
	replace `V'=3.5 if t==3
	replace `V'=5 if t==4
	replace `V'=6.5 if t==5
	replace `V'=8 if t==6
	local xlabel xlabel( ///
	0.5 "Mothers" ///
	2 "Fathers" ///
	3.5 "Mothers" ///
	5 "Fathers" ///
	6.5 "Mothers" ///
	8 "Fathers" ///
		,  notick )  
	local legend  legend(off)
	local title ytitle(" ")
	local specs xtitle(" ") xtick(none) graphregion(color(white)) yscale(range(0 .7)) ylabel(0 (.1) .7) ytick(0 (.1) .7)
	local text  text(0.675 1.2 "Panel A:", size(medium)) ///
				text(0.64 1.2 "Parent choices", size(medium)) ///
				text(0.675 4.2 "Panel B:", size(medium)) ///
				text(0.64 4.2 "Child perspective", size(medium)) ///
				text(0.675 7.2 "Panel C", size(medium)) ///
				text(0.64 7.2 "Parent perspective", size(medium)) 
	local line xline(2.75, lpattern(solid)) xline(5.75, lpattern(solid)) 
	
	local condition1  `V'==0.5 | `V'==3.5 | `V'==6.5 
	local condition2  `V'==2  | `V'==5 | `V'==8 
	graph twoway (bar h `V' if (`condition1'),fcolor(gs16) lcolor(gs0) lwidth(thin)) ///
	(bar h `V' if (`condition2'),fcolor(gs16) lcolor(gs0) lwidth(thin)) ///
	(rcap hd ld `V' if ((`condition1') | (`condition2') ), lcolor(gs0)), ///
	`specs'  `legend' `title' `xlabel' `xscale' `text' `line'
	
	restore
}		


***********
* Table 1 *
*********** PANEL A
{
* Panel A
use "$Data/school_grades", clear   

*for all schools
mean math_grade_boys math_grade_girls ///
bokmal_boys bokmal_girls ///
nynorsk_boys nynorsk_girls ///
norwegian_oral_boys norwegian_oral_girls ///
english_grade_boys english_grade_girls ///
english_oral_grade_boys english_oral_grade_girls 

*for invited sample
mean math_grade_boys math_grade_girls ///
bokmal_boys bokmal_girls ///
nynorsk_boys nynorsk_girls ///
norwegian_oral_boys norwegian_oral_girls ///
english_grade_boys english_grade_girls ///
english_oral_grade_boys english_oral_grade_girls, over(participate)

* Panel B 
use "$Data/admindata", clear   
keep if child==1

estpost ttest mother cbrokenh cmarried page pbio foreign brothers sisters parentalincome pcollege studspec_Y1 sspec_Y1_imp grade10_GPA, by(girl)
esttab using "$Results/Table1PanelB.csv", replace cells(mu_1 mu_2 p) wide nonumber nostar
}

***********
* Table 2 *
***********
{
use "$Data/admindata", clear   

* i. Panel A
eststo clear
eststo: reg pchoice girl if child==0, r
eststo: reg pchoice girl pbskill points3 if child==0, r
eststo: reg pchoice girl pbskill points3 prisk prisk_q if child==0, r
eststo: reg pchoice girl pbskill points3 prisk prisk_q parentalincome pcollege mother if child==0 & oneparincmissing!=1 & pcollege!=., r
esttab using "$Results/Table2PanelA.csv", replace ///
	label nonumber keep(girl pbskill points3 prisk prisk_q) r2 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)

* i. Panel B 
eststo clear
eststo: reg cchoice girl if child==1, r
eststo: reg cchoice girl cbskill points3 if child==1, r
eststo: reg cchoice girl cbskill points3 crisk crisk_q if child==1, r
eststo: reg cchoice girl cbskill points3 crisk crisk_q parentalincome pcollege mother if child==1 & oneparincmissing!=1 & pcollege!=., r
esttab using "$Results/Table2PanelB.csv", replace ///
	label nonumber keep(girl cbskill points3 crisk crisk_q) r2 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}

***********
* Table 3 *
***********
{
use "$Data/experimentdata.dta", clear 
eststo clear

eststo: reg pchoice girl if child==0, r
eststo: reg pchoice girl pbelief if child==0, r
eststo: reg pchoice girl pbelief pself if child==0, r
eststo: reg pchoice girl pbelief pself if child==0 & girl==1, r
eststo: reg pchoice girl pbelief pself if child==0 & girl==0, r
esttab using "$Results/Table3.csv", replace ///
	label nonumber keep(girl pbelief pself) r2 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}

***********
* Table 4 *
*********** 
{
use "$Data/admindata", clear   
eststo clear

eststo: reg pbelief girl if child==0, r 
eststo: reg pbelief girl points3 cbskill pbskill if child==0, r 
eststo: reg pbelief girl points3 cbskill pbskill crisk crisk_q prisk prisk_q if child==0, r
eststo: reg pbelief girl points3 cbskill pbskill crisk crisk_q prisk prisk_q parentalincome pcollege mother if child==0 & oneparincmissing!=1 & pcollege!=., r
esttab using "$Results/Table4.csv", replace ///
	label nonumber keep(girl points3 cbskill pbskill crisk crisk_q prisk prisk_q) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}

***********
* Table 5 *
***********
{
use "$Data/admindata", clear   
eststo clear

eststo: areg sspec_Y1_imp pchoice girl 						if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice girl mother pcollege parentalincome 		if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust

eststo: areg sspec_Y1_imp cchoice girl 				     		if child==1 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp cchoice girl mother pcollege parentalincome 		if child==1 & oneparincmissing!=1 & pcollege!=., a(school) robust

eststo: areg sspec_Y1_imp pchoice cchoice girl 					if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice cchoice girl mother pcollege parentalincome	if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust

eststo: areg sspec_Y1_imp pchoice cchoice pbskill cbskill prisk crisk prisk_q ///
crisk_q girl 									if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice cchoice pbskill cbskill prisk crisk prisk_q ///
crisk_q girl mother pcollege parentalincome 					if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice cchoice pbskill cbskill prisk crisk prisk_q ///
crisk_q girl grade10_GPA mother pcollege parentalincome 			if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust

esttab using "$Results/Table5.csv", replace ///
	label nonumber keep(cchoice pchoice grade10_GPA) r2 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}

***********
* Table 6 *
***********
{
use "$Data/admindata", clear  
eststo clear

eststo: areg sspec_Y1_imp  pchoice cchoice girl					if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp  pchoice cchoice pself girl				if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp  pchoice cchoice pbelief girl				if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp  pchoice cchoice pbelief pself girl			if child==0 & oneparincmissing!=1 & pcollege!=., a(school) robust

esttab using "$Results/Table6.csv", replace ///
	label nonumber keep(pchoice cchoice pbelief pself) r2 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}

***********
* Table 7 *
***********
{
use "$Data/experimentdata.dta", clear 
eststo clear

eststo: reg pchoice pbelief pself if child==0 & mother==1, r
eststo: reg pchoice pbelief pself if child==0 & mother==0, r

esttab using "$Results/Table7.csv", replace ///
	label nonumber keep(pbelief pself pchoice) r2 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}
	
***********
* Table 8 *
***********
{
use "$Data/admindata", clear   
eststo clear

eststo: areg sspec_Y1_imp pchoice girl 					if child==0 & oneparincmissing!=1 & mother!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice girl pcollege parentalincome 		if child==0 & oneparincmissing!=1 & mother!=1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice cchoice girl pcollege parentalincome 	if child==0 & oneparincmissing!=1 & mother!=1 & pcollege!=., a(school) robust

eststo: areg sspec_Y1_imp pchoice girl 					if child==0 & oneparincmissing!=1 & mother==1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice girl pcollege parentalincome 		if child==0 & oneparincmissing!=1 & mother==1 & pcollege!=., a(school) robust
eststo: areg sspec_Y1_imp pchoice cchoice girl pcollege parentalincome 	if child==0 & oneparincmissing!=1 & mother==1 & pcollege!=., a(school) robust

esttab using "$Results/Table8.csv", replace ///
	label nonumber keep(pbelief pself pchoice cchoice) r2 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}

***********
* Table 9 *
***********
{
use "$Data/admindata", clear   
eststo clear

eststo: reg cchoice pself if child==0, r
eststo: reg cchoice pself if child==0 & mother==0 & girl==0, r
eststo: reg cchoice pself if child==0 & mother==0 & girl==1, r
eststo: reg cchoice pself if child==0 & mother==1 & girl==0, r
eststo: reg cchoice pself if child==0 & mother==1 & girl==1, r

eststo: reg cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if child==0, r
eststo: reg cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if child==0 & mother==0 & girl==0, r
eststo: reg cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if child==0 & mother==0 & girl==1, r
eststo: reg cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if child==0 & mother==1 & girl==0, r
eststo: reg cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if child==0 & mother==1 & girl==1, r
	
 esttab using "$Results/Table9.csv", replace ///
	label nonumber keep(pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
}

******************************************
* Multiple Hypothesis Testing Correction *
******************************************
{
* i. Table 1
use "$Data/admindata", clear   
keep if child==1

mhtreg (mother girl) (cbroken girl) (cmarried girl) (page girl) (pbio girl) (foreign girl) (brothers girl) (sisters girl) (parentalincome girl) (pcollege girl)

* ii. Table 2
use "$Data/admindata", clear   
eststo clear

mhtreg (cchoice girl if child==0) (pchoice girl if child==0) 
mhtreg (cchoice girl points3 cbskill if child==0) (pchoice girl points3 pbskill if child==0), robust 
mhtreg (cchoice girl points3 cbskill crisk crisk_q if child==0) (pchoice girl points3 pbskill prisk prisk_q if child==0), robust 
mhtreg (cchoice girl points3 cbskill crisk crisk_q parentalincome pcollege mother if child==0) (pchoice girl points3 pbskill prisk prisk_q parentalincome pcollege mother if child==0), robust

* iii. Table 5
use "$Data/admindata", clear   
eststo clear
tab school, gen(SCH)

mhtreg (sspec_Y1_imp pchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 if oneparincmissing!=1 & pcollege!=. & child==0) (sspec_Y1_imp cchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 parentalincome pcollege mother if oneparincmissing!=1 & pcollege!=. & child==0), robust
mhtreg (sspec_Y1_imp pchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 if oneparincmissing!=1 & pcollege!=. & child==0) (sspec_Y1_imp cchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 parentalincome pcollege mother if oneparincmissing!=1 & pcollege!=. & child==0), robust

* iii. Table 8
use "$Data/admindata", clear   
eststo clear
tab school, gen(SCH)


mhtreg (sspec_Y1_imp pchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 if mother==1 & oneparincmissing!=1 & pcollege!=. & child==0 ) (sspec_Y1_imp pchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 if mother==0 & oneparincmissing!=1 & pcollege!=. & child==0), robust
mhtreg (sspec_Y1_imp pchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 parentalincome pcollege mother if mother==1 & oneparincmissing!=1 & pcollege!=. & child==0 ) (sspec_Y1_imp pchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 parentalincome pcollege mother if mother==0 & oneparincmissing!=1 & pcollege!=. & child==0), robust
mhtreg (sspec_Y1_imp pchoice cchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 parentalincome pcollege mother if mother==1 & oneparincmissing!=1 & pcollege!=. & child==0 ) (sspec_Y1_imp pchoice cchoice girl SCH1 SCH2 SCH3 SCH4 SCH5 SCH6 SCH7 SCH8 SCH9 SCH10 SCH11 SCH12 SCH13 SCH14 SCH15 parentalincome pcollege mother if mother==0 & oneparincmissing!=1 & pcollege!=. & child==0), robust


* iv. Table 9
use "$Data/admindata", clear   
eststo clear

keep if child==0

gen Group=0
replace Group=1 if mother!=1 & girl!=1
replace Group=2 if mother!=1 & girl==1
replace Group=3 if mother==1 & girl!=1
replace Group=4 if mother==1 & girl==1

mhtreg (cchoice pself if Group==1) (cchoice pself if Group==2)  (cchoice pself if Group==3) (cchoice pself if Group==4), cluster(npid) 
mhtreg (cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if Group==1) (cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if Group==2)  (cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if Group==3) (cchoice pself points3 crisk crisk_q parentalincome pcollege prisk prisk_q if Group==4), cluster(npid)  
}




* END OF DOFILE *









